how to handle exceptions in rest api